﻿/////////////////////////////////////////////////////////////////
//File: BlogInfo.cs
//Description: 
//Copyright© 2011 Moliu
//History:
//  2011-3-26 18:11:19    CodeSmith5.0.1    Original Version
/////////////////////////////////////////////////////////////////
using System;
using System.Collections;
using MAF.Common;
using System.Collections.Generic;
using My.Blog.Repository;

namespace My.Blog
{
    /// <summary>
    /// Business entity used to model Blog
    /// </summary>
    [Serializable]
    public class MyBlog : BaseEntity
    {
        /// <summary>
        /// 构造方法
        /// </summary>
        public MyBlog() : base()
        {
        }

        #region 属性变量

        private string _name;

        #endregion

        #region 属性

        /// <summary>
        /// 所有者
        /// </summary>
        public string Owner { get; set; }

        /// <summary>
        /// 介绍
        /// </summary>
        public string Introduction { get; set; }

        /// <summary>
        /// 座右铭
        /// </summary>
        public string Declaration { get; set; }

        /// <summary>
        /// 密码
        /// </summary>
        public string Password { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public string State { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string Name 
        {
            get
            {
                return _name;
            }
            set
            {
                if (string.IsNullOrWhiteSpace(value))
                    throw new ArgumentNullException("博客名不能为空");

                _name = value;
            }
        }
        
        #endregion

        #region 枚举

        /// <summary>
        /// 0 正常 ( Enable)
        /// 1管理员关闭(Disable)，表示博客已经被屏蔽，除管理员外无人能够访问。
        /// 2 管理员关闭写(ReadOnly)，表示博客对于博主来说是只写的
        /// 3管理员关闭读(WriteOnly)，表示博客对于博主来说是只读的
        /// 4博主关闭(Close)，表示对除博主外的其他用户屏蔽。
        /// </summary>
        public enum StateEnum
        {
            Enable = 0,
            Disable = 1,
            ReadOnly = 2,
            WriteOnly = 3,
            Close = 4
        }

        #endregion

        #region 方法

        /// <summary>
        /// 增加本博客的分类
        /// </summary>
        /// <param name="info"></param>
        public void AddCategory(CategoryInfo info)
        {
            BlogRepo.Categories.Add(info);
        }

        /// <summary>
        /// 修改本博客分类
        /// </summary>
        /// <param name="info"></param>
        public void UpdateCategory(CategoryInfo info)
        {
            BlogRepo.Categories.Update(info);
        }

        /// <summary>
        /// 删除本博客分类
        /// </summary>
        /// <returns></returns>
        public int RemoveCategory(Guid id)
        {
            return BlogRepo.Categories.Remove(id);
        }

        /// <summary>
        /// 获取本博客的分类列表
        /// </summary>
        /// <returns></returns>
        public List<CategoryInfo> GetCategries()
        {
            return BlogRepo.Categories.GetByQuery(null);
        }

        /// <summary>
        /// 获取本博客的某个分类
        /// </summary>
        /// <returns></returns>
        public CategoryInfo GetCategory(Guid catId)
        {
            return BlogRepo.Categories.GetById(catId);
        }

        /// <summary>
        /// 增加文章
        /// </summary>
        /// <param name="entity"></param>
        public void AddArticle(Guid catId, Article entity)
        {
            CategoryInfo cat = GetCategory(catId);
            if (null == cat)
                throw new ArgumentException("没有找到指定的分类");

            BlogRepo.Articles.Add(entity);
        }

        /// <summary>
        /// 修改文章内容
        /// </summary>
        /// <param name="entity"></param>
        public void UpdateArticle(Article entity)
        {
            BlogRepo.Articles.Update(entity);
        }

        /// <summary>
        /// 删除文章
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int RemoveArticle(Guid id)
        {
            return BlogRepo.Articles.Remove(id);
        }

        /// <summary>
        /// 获取本博客的文章列表
        /// </summary>
        /// <returns></returns>
        public List<Article> GetArticles()
        {
            return BlogRepo.Articles.GetByQuery(null);
        }

        /// <summary>
        /// 获取本博客的文章
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Article GetArticle(Guid id)
        {
            return BlogRepo.Articles.GetById(id);
        }

        /// <summary>
        /// 获取本博客的访问次数
        /// </summary>
        /// <returns></returns>
        public int GetVisistedCount()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}